
uniform float speed;
vec2 center = vec2(1.0 ,1.);
float length2(vec2 p) { return dot(p, p); }

float noise(vec2 p){
  return fract(sin(fract(sin(p.x) * (4313.13311)) + p.y) * 3131.0011);
}

float worley(vec2 p) {
  float d = 1e30;
  for (int xo = -1; xo <= 1; ++xo)
  for (int yo = -1; yo <= 1; ++yo) {
    vec2 tp = floor(p) + vec2(xo, yo);
    d = min(d, length2(p - tp - vec2(noise(tp))));
  }
  return 3.*exp(-4.*abs(2.*d - 1.));
}

float fworley(vec2 p) {
  float iTime = czm_frameNumber * speed / 1000. ;
  return sqrt(sqrt(sqrt(
    pow(worley(p + iTime), 2.) *
    worley(p*2. + 1.3 + iTime*.05) *
    worley(p*4. + 2.3 + iTime*.025) *
    worley(p*8. + 3.3 + iTime*.0125) *
    worley(p*32. + 4.3 + iTime*.0125) *
    sqrt(worley(p * 64. + 5.3 + iTime * .00625)) *
    sqrt(sqrt(worley(p * 128. + 7.3))))));
}

czm_material czm_getMaterial(czm_materialInput materialInput){
  czm_material material = czm_getDefaultMaterial(materialInput);
  vec2 v_st = materialInput.st; // 获取uv坐标
  
  vec2 uv = v_st;
  float t = fworley(uv * center.xy );
  t *= exp(-length2(abs(2.* uv - 1.)));
  float r = length(abs(2.* uv - 1.) * center.xy);
  vec4 fragColor = vec4(t * vec3(4.8, 7.8*t, .1 + pow(t, 2.-t)), 1.);

  material.diffuse = fragColor.rgb;
  return material;
}